package jin.si.com.xc;

/**
 * @description:
 * @ClassName SiSuo
 * @Author MT
 * @Date 2021/7/3 15:39
 **/
public class SiSuo extends Thread{

    //private static final String obj1;

    boolean flag;

    public SiSuo(){

    }

    public SiSuo(boolean flag){
        this.flag=flag;
    }

    @Override
    public void run() {
       while(true){
           //同步代码块锁
           if(flag){
               synchronized (TestSiSuo.obj1){
                   System.out.println("if锁1");
                   synchronized (TestSiSuo.obj2){
                       System.out.println("if锁2");
                   }
               }
           }else{
               synchronized (TestSiSuo.obj2){
                   System.out.println("else锁2");
                   synchronized (TestSiSuo.obj1){
                       System.out.println("else锁1");
                   }
               }
           }
       }

    }



}
